package com.zhw.studententity;

import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import com.zhw.entity.StudentEntity;
import org.apache.poi.ss.usermodel.Workbook;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @auther weizhang52 on 2018/11/21
 * @description
 * @modify
 */
public class ExportEntity {

    public static void main(String[] args) {

        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        List<StudentEntity> list=new ArrayList<>();
        try {
            list.add(new StudentEntity("1","司法局1",1, sdf.parse("2027-06-22"),sdf.parse("2027-06-22")));
            list.add(new StudentEntity("2","司法局2",2, sdf.parse("2027-06-22"),sdf.parse("2027-06-22")));
            list.add(new StudentEntity("3","司法局3",1, sdf.parse("2027-06-22"),sdf.parse("2027-06-22")));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams("计算机一班学生","学生"),
                StudentEntity.class, list);
        File savefile = new File("D:/easypoi/");
        if (!savefile.exists()) {
            savefile.mkdirs();
        }
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream("D:/easypoi/StudentEntity.xlsx");
            workbook.write(fos);
            fos.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }


    }


}
